/**
 * 使用渠道
 * @author linfeng
 * @since 2019/12/24
 */
layui.extend({
    zmnExportUtil: '{/}/static/js/zmn.excel.util'
}).define(['index', 'form', 'table', 'laypage', 'layedit','zmnExportUtil','laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    let layDate = layui.laydate;
    var layedit = layui.layedit;
    var zmnExportUtil =layui.zmnExportUtil;

    form.render();

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        defaultToolbar: ['exports'],
        limit: json.pageSize,
        height: 'full-195',
        done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        },
    });

    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    var ids = new Array();

    // 表格复选框监听
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.relateId);
    });

    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == 'add') {
            layer.open({
                type: 2,
                title: '新增使用渠道',
                area: ['90%', '80%'],
                content: '/channel/tariff/listAjax.action?tariffId=' + json.vo.tariffId
            });
            return false;
        }

        if (obj.event == 'delete') {
            if (ids.length === 0) {
                return layer.alert("请选择至少一条数据！");
            }
            layer.confirm('从"' + json.faultTariff.tariffName + '"里面删除选中的使用渠道吗？\n' +
                '\n' +
                '成功删除后，渠道对应的价格表将不再使用该价格表', {
                btn: ['确定', '取消']
            }, function () {
                zmnPage.ajaxSimple("/channel/tariff/delete.action", {ids: ids.join(",")}, 1000);
            });
            return false;
        }

        //导出excel
        if(obj.event=='CUSTOM_EXPORT'){
            zmnExportUtil.doExportExcel('zmn-table','标准列表');
        }
    });


    //对外暴露的接口
    exports('channel_tariff_list_js', {});
});

